package com.example.chcrm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chcrm.entity.common.ResponseMsg;
import com.example.chcrm.entity.common.ServletUtils;
import com.example.chcrm.entity.employee.EmployeeVo;
import com.example.chcrm.entity.supplier.WaterwaySupplierInfo;
import com.example.chcrm.service.WaterwaySupplierInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 邹
 * @Date 2025/4/20 23:34
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/waterway")
@CrossOrigin // 允许跨域访问
public class WaterwaySupplierInfoController {

    @Autowired
    private WaterwaySupplierInfoService waterwaySupplierInfoService;
    /**
     * 分页查询公路供应商
     */
    @PostMapping("/pageList")
    public ResponseMsg<IPage<WaterwaySupplierInfo>> pageList(@RequestBody WaterwaySupplierInfo highwaySupplierInfo) {
        //获取登录用户信息
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return waterwaySupplierInfoService.pageList(highwaySupplierInfo, empVo);
    }

    /**
     * 新增公路供应商
     */
    @PostMapping("/add")
    public ResponseMsg<Object> add(@RequestBody WaterwaySupplierInfo customerInfo) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return waterwaySupplierInfoService.add(customerInfo, empVo);
    }
    /**
     * 详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public ResponseMsg<Object> detail(@PathVariable String id) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return waterwaySupplierInfoService.detail(id);
    }

    /**
     * 禁用/启用/发送审核
     */
    @PostMapping("/disable")
    public ResponseMsg<Object> disable(@RequestBody WaterwaySupplierInfo customerInfo) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;

        return  waterwaySupplierInfoService.disable(customerInfo,empVo);
    }

    /**
     * 修改供应商信息
     */
    @PostMapping("/update")
    public ResponseMsg<Object> update(@RequestBody WaterwaySupplierInfo customerInfo) {
        HttpServletRequest request = ServletUtils.getRequest();
        EmployeeVo empVo = request != null ? (EmployeeVo) request.getAttribute("empVo") : null;
        return waterwaySupplierInfoService.update(customerInfo,empVo);
    }
    /**
     * 提取可选水路供应商
     */
    @GetMapping("/selectAllWaterSupplier")
    public ResponseMsg<Object> selectAllHighSupplier() {
        return waterwaySupplierInfoService.selectAllWaterSupplier();
    }
}


